#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define endl '\n'
#define pb push_back
#define rep(i,a,n) for(ll i =a;i<n;i++)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define mod 1000000007
#define fastio() ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define ss second
#define ff first
#define gcd __gcd
#define all(x) x.begin(),x.end()
#define wttt while(t--)
#define printall(v) for(auto value:v) cout<<value<<" ";cout<<endl;
#define mp make_pair
#define PI 3.141592653589793238462643383279502884197
#define ub upper_bound
#define lb lower_bound
#define read(v,n) rep(i,0,n)cin>>v[i];
#define count_set_bits __builtin_popcountll
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef pair<ll,ll>pll;
typedef map<ll,ll> mll;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll,ll>> vpll;
typedef vector<ld> vld;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > pbds;
ld eps = 1e-9;
/*
For using ordered_set :
1. *s.find_by_order(k) --> Returns the element present at index k.
2. s.order_of_key(k) --> Returns the number of elements smaller than k.
*/
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
// void _print(pbds v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T, class V> void _print(multimap <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(unordered_set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(multimap <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
void solve()
{
ll n;cin>>n;
vll v(n);
rep(i,0,n)
{
v[i] = i + 1;
}
vpll ans;
for(ll i = n-2; i >= 2; i--)
{
ll val = v[n-1]/v[i];
if(v[n-1] % v[i] != 0)
{
val++;
}
if(v[i] <= val)
{
ans.pb({n-1, i});
v[n-1] = val;
}
ans.pb({i, n-1});
v[i] = 1;
}
while(v[n-1] != 1)
{
ll val = v[n-1]/v[1];
if(v[n-1] % v[1] != 0)
{
val++;
}
v[n-1] = val;
ans.pb({n-1, 1});
}
cout<<ans.size()<<endl;
for(auto val:ans)
{
cout<<val.ff + 1<<" "<<val.ss + 1<<endl;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("Error.txt", "w", stderr);
#endif
fastio();
ll t=1;
//pre();
cin>>t;
for(ll ttt = 1;ttt<=t;ttt++)
{
// cout<<"Case #"<<ttt<<": ";
solve();
}
return 0;
}
1356. Sort Integers by The Number of 1 Bits | 922. Sort Array By Parity II |
344. Reverse String | 1047. Remove All Adjacent Duplicates In String |
977. Squares of a Sorted Array | 852. Peak Index in a Mountain Array |
461. Hamming Distance | 1748. Sum of Unique Elements |
897. Increasing Order Search Tree | 905. Sort Array By Parity |
1351. Count Negative Numbers in a Sorted Matrix | 617. Merge Two Binary Trees |
1450. Number of Students Doing Homework at a Given Time | 700. Search in a Binary Search Tree |
590. N-ary Tree Postorder Traversal | 589. N-ary Tree Preorder Traversal |
1299. Replace Elements with Greatest Element on Right Side | 1768. Merge Strings Alternately |
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |
1822. Sign of the Product of an Array | 1464. Maximum Product of Two Elements in an Array |
1323. Maximum 69 Number | 832. Flipping an Image |
1295. Find Numbers with Even Number of Digits | 1704. Determine if String Halves Are Alike |
1732. Find the Highest Altitude | 709. To Lower Case |
1688. Count of Matches in Tournament | 1684. Count the Number of Consistent Strings |